package com.turing.manage.listener;
import javax.servlet.ServletRequest;
/**
 * @desc   Request请求监听器记录ip
 * @author wyh
 * @time   2022-01-06
 */
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;

public class MyServletRequestListener  implements ServletRequestListener {

/**
 * @desc 1.请求销毁的时候触发
 */
@Override
public void requestDestroyed(ServletRequestEvent sre) {

	//1.立足ServletRequestEvent这个事件对象获取servletRequest对象
	ServletRequest servletRequest = sre.getServletRequest();
	
	//2.获取客户端销毁时候的ip
	System.out.println(servletRequest.getRemoteAddr()+":请求销毁");
	
	//3.接下来自己感兴趣的话，可以尝试着去写一些黑白名单
	
}

/**
 * @desc 2.请求初始化的时候触发
 */
@Override
public void requestInitialized(ServletRequestEvent sre) {
         
	//1.立足ServletRequestEvent这个事件对象获取servletRequest对象
	ServletRequest servletRequest = sre.getServletRequest();
	
	//2.获取客户端请求时候的ip
	System.out.println(servletRequest.getRemoteAddr()+":请求初始化");
}

}
